<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="">
        <input type="text" name="name">
        <input type="text" name="age">
        <input type="text" name="sex">
        <button>提交</button>
    </form>
</body>


<script>
    const oBtn = document.querySelector("button")
    const oName = document.querySelector("form input[name=name]")
    const oAge = document.querySelector("form input[name=age]")
    const oSex = document.querySelector("form input[name=sex]")

    oBtn.onclick = function () {
        const nameData = oName.value
        const ageData = oAge.value
        const sexData = oSex.value


        const xhr = new XMLHttpRequest()

        xhr.open("post", "http://127.0.0.1:8181/post",true)

        xhr.send(`name=${nameData}&age=${ageData}&sex=${sexData}`)

        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 & xhr.status >= 200 & xhr.status <= 299) {
                console.log(xhr.responseText);
            }
        }


        return false
    }
</script>

</html>